<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('core/core')->checklogin('','',true);
	$_SESSION['memberid']=$this->model('member')->checkmember();
	$return['list']=array();
	$return['params']['status']=0;
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	set_html('title','我的工作');
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	$params=array('memberid'=>$_SESSION['memberid'],'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$list=pdo_getslice('jy_51job_gong',$params,array($pindex,$psize),$total,$fields,'','id desc');	
	if($list){
		foreach($list as &$item){
			$job=pdo_get('jy_51job_job',array('id'=>$item['jobid'],'uniacid'=>$_SESSION['uniacid']));
			$item['pay']=$job['pay'];
			$item['city']=$job['city'];
			$item['onlinetime']=json_decode($job['onlinetime'],true);
			$item['images']=json_decode($job['images'],true);
			$item['jobinfo']=json_decode($item['jobinfo'],true);
			$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			$item['baotypetitle']=$this->job_paytype2[$job['paytype']].'结('.$this->job_baotype[$job['baotype']].'版)';
			$item['merchname']=pdo_getcolumn('jy_51job_merch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['merchid']),'title');
			$item['statustitle']=$this->gong_status[$item['status']];
			$item['typetitle']=$this->job_type[$item['jobinfo']['type']];
			$item['paytypetitle']=$this->job_paytype[$item['jobinfo']['paytype']];
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			$item['signlog']=pdo_get('jy_51job_signlog',array('uniacid'=>$_SESSION['uniacid'],'gongid'=>$item['id']),'','createtime desc');
			$item['signlog']['uptime2']=date('Y-m-d H:i:s', $item['signlog']['uptime']);
			$item['signlog']['starttime2']=$item['signlog']['starttime']?date('Y-m-d H:i:s', $item['signlog']['starttime']):'';
			$item['signlog']['endtime2']=$item['signlog']['endtime']?date('Y-m-d H:i:s', $item['signlog']['endtime']):'';
			$item['maplog']=pdo_get('jy_51job_maplog',array('uniacid'=>$_SESSION['uniacid'],'gongid'=>$item['id']),'','createtime desc');
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getxieyi'){
	$gongid=intval($_RQ['gongid']);
	$gong=pdo_get('jy_51job_gong',array('id'=>$gongid,'uniacid'=>$_SESSION['uniacid']));
	$xieyitpl=pdo_get('jy_51job_xieyitpl',array('merchid'=>$gong['merchid'],'uniacid'=>$_SESSION['uniacid'],'status'=>1));
	if(!$xieyitpl['id']){
		exi('该企业还未完善协议！','error');
	}
	$return['xieyi']=$xieyitpl;
	exi($return);
}
if($_RQ['op']=='postxieyi'){
	$post=get_postdata();
	$gongid=intval($_RQ['gongid']);
	$ismerch=intval($_RQ['ismerch']);
	$gong=pdo_get('jy_51job_gong',array('id'=>$gongid,'uniacid'=>$_SESSION['uniacid']));
	if($ismerch){
		if($gong['isxieyiuser'] && $gong['ishetong'] && $gong['ishetonguser']){
			$status=1;
		}
		$update=array('isxieyi'=>1,'status'=>$status);
	}else{
		if($gong['isxieyi'] && $gong['ishetong'] && $gong['ishetonguser']){
			$status=1;
		}
		$update=array('isxieyiuser'=>1,'status'=>$status);
	}
	pdo_update('jy_51job_gong',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$gongid));
	if($ismerch){
		exi('签署成功！','','/merch.gong/');
	}else{
		exi('签署成功！','','/gong/');
	}
}
if($_RQ['op']=='gethetong'){
	$gongid=intval($_RQ['gongid']);
	$gong=pdo_get('jy_51job_gong',array('id'=>$gongid,'uniacid'=>$_SESSION['uniacid']));
	$hetongtpl=pdo_get('jy_51job_hetongtpl',array('merchid'=>$gong['merchid'],'uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$hetongtpl['images']=json_decode($hetongtpl['images'],true);
	if(!$hetongtpl['id']){
		exi('该企业还未完善合同！','error');
	}
	$return['hetong']=$hetongtpl;
	exi($return);
}
if($_RQ['op']=='posthetong'){
	$post=get_postdata();
	$gongid=intval($_RQ['gongid']);
	$ismerch=intval($_RQ['ismerch']);
	$gong=pdo_get('jy_51job_gong',array('id'=>$gongid,'uniacid'=>$_SESSION['uniacid']));
	if($ismerch){
		if($gong['isxieyiuser'] && $gong['isxieyi'] && $gong['ishetonguser']){
			$status=1;
		}
		$update=array('ishetong'=>1,'status'=>$status);
	}else{
		if($gong['isxieyiuser'] && $gong['isxieyi'] && $gong['ishetong']){
			$status=1;
		}
		$update=array('ishetonguser'=>1,'status'=>$status);
	}
	pdo_update('jy_51job_gong',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$gongid));
	if($ismerch){
		exi('签署成功！','','/merch.gong/');
	}else{
		exi('签署成功！','','/gong/');
	}
}
if($_RQ['op']=='startsign'){
	$post=get_postdata();
	$gongid=intval($_RQ['gongid']);
	$gong=pdo_get('jy_51job_gong',array('id'=>$gongid,'uniacid'=>$_SESSION['uniacid']));
	$this->model('job')->startsign($gong,$post);
	exi('打卡成功！','','/gong/');
}
if($_RQ['op']=='endsign'){
	$post=get_postdata();
	$gongid=intval($_RQ['gongid']);
	$gong=pdo_get('jy_51job_gong',array('id'=>$gongid,'uniacid'=>$_SESSION['uniacid']));
	$this->model('job')->endsign($gong,$post);
	exi('打卡成功！','','/gong/');
}